#include <stdio.h> 
#include <stdlib.h>
#include <time.h>
#include <omp.h>

int main(int argv,char **argc)
{
	clock_t Start,End;
	Start = clock();	
	FILE* in = fopen("in.txt","r");
	int i,n,k,stop;
	int pn = 4;
	int *array;
	fscanf(in,"%d",&n);
	array = malloc(sizeof(int)*n);
	for(i = 0;i < n;i++)
		fscanf(in,"%d",&array[i]);	
	k = 0;
	stop = 1;
	if(argv > 1)
		sscanf(argc[1],"%d\n",&pn);
	while(stop >= 1)
	{
		stop = 0;
		#pragma omp parallel for schedule(guided,pn) reduction(+:stop)
		for(i = k%2;i < n-1;i+=2)
		{
			if(array[i] > array[i+1])
			{
				int t = array[i];
				array[i] = array[i+1];
				array[i+1] = t;
				stop = 1;
			}
		}
		k++;
	}
	End = clock();
	/*for(i = 0;i < n;i++)
		printf("%d ",array[i]);
	printf("\n");*/
	int Time = End-Start;
	printf("%d\n",Time);
	return 0;
}
